package com.jy.controller;


import com.jy.common.enums.ResponseWrapper;
import com.jy.common.model.good.result.DeleteCartGoodsParam;
import com.jy.common.tool.CommonTool;
import com.jy.service.CartService;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 购物车表 前端控制器
 * </p>
 *
 * @author fzg
 * @since 2024-11-18
 */
@RestController
@RequestMapping("/cart")
public class CartController {

    private final CartService cartService;

    public CartController(CartService cartService) {
        this.cartService = cartService;
    }

    /**
     * 获取购物车信息
     * @param request 用于获取token
     * @return ResponseWrapper
     */
    @GetMapping("/getMyCartInfo")
    public ResponseWrapper getMyCartInfo(HttpServletRequest request) {
        return cartService.getMyCartInfo(CommonTool.getUserAidByToken(request));
    }


    /**
     * 删除购物车商品
     * @param params 购物车里剩下的商品
     * @return ResponseWrapper
     */
    @PostMapping("/deleteCartGoods")
    public ResponseWrapper deleteCartGoods(@RequestBody List<DeleteCartGoodsParam> params) {
        return cartService.deleteCartGoods(params);
    }

}
